#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2025/3/25 11:11
# @File           : need.py
# @IDE            : PyCharm
# @desc           : 描述

from sqlalchemy.orm import Mapped, mapped_column, relationship
from db.db_base import BaseModel, AuditModel
from sqlalchemy import ForeignKey, String, Text


class DCTaskNeed(AuditModel):
    __tablename__ = "dc_dispatch_need"
    __table_args__ = (
        {'comment': '物料或辅料需求'}
    )
    ticket_id: Mapped[int] = mapped_column(
        String(50),
        ForeignKey("dc_dispatch_task.ticket_id", ondelete="CASCADE"),
        comment="工单ID"
    )
    task = relationship("DCTask", foreign_keys=ticket_id, back_populates="needs")
    
    need_type: Mapped[str] = mapped_column(String(20), comment="需求资源类型，如辅料，物料，设备等")

    name: Mapped[str] = mapped_column(String(20), index=True, comment="资源名")  # 需求资源编号或名称
    type: Mapped[str] = mapped_column(String(20), nullable=True, comment="资源型号")
    number: Mapped[str] = mapped_column(String(20), nullable=True, comment="所需数量")  # 需求数量
    unit: Mapped[str] = mapped_column(String(20), nullable=True, comment="需求单位")

    remark: Mapped[str] = mapped_column(Text, nullable=True, comment="备注")
